﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 花店管理系统.start
{
    public partial class ChangePwd : Form
    {
        public ChangePwd()
        {
            InitializeComponent();
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            NewMethod();
            DB.cn.Close();

            void NewMethod()
            {
                if (txtOldpwd.Text == "")
                {
                    MessageBox.Show("请输入原密码");
                }
                else
                {
                    DB.GetCn();
                    string str = "select * from Twoker where t_name= '" + txtName.Text
                        + "'and phone='" + txtOldpwd.Text + "'";
                    DataTable dt = DB.GetDataSet(str);
                    if (dt.Rows.Count < 1)
                    {
                        MessageBox.Show("原密码错误，请重新输入");
                    }
                    else
                    {
                        if (txtNewpwd.Text == "" || txtNewpwd2.Text == "")
                        {
                            MessageBox.Show("请输入新密码");
                        }
                        else
                        {
                            if (txtNewpwd.Text != txtNewpwd2.Text)
                            {
                                MessageBox.Show("两次新密码不一致，请重新输入");
                            }
                            else
                            {
                                string sdr = "update Twoker set phone='"
                                    + txtNewpwd.Text + "'where t_name='" + txtName.Text.Trim() + "'";
                                DB.SqlEx(sdr);
                                MessageBox.Show("修改成功");
                                this.Close();
                            }
                        }
                    }
                }
            }
        }

        private void ChangePwd_Load(object sender, EventArgs e)
        {
            txtName.Text = Login.username;
        }

        private void btnCance_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
